package org.qengine.controller;

import org.qengine.entity.DataDictEntity;
import org.qengine.entity.KnowEntity;
import org.qengine.service.KnowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("know/")
public class KnowController {
    @Autowired
    private KnowService knowService;


    public KnowController(KnowService knowService) {
        this.knowService = knowService;
    }

    // 增

    @PostMapping("/add")
    public String add(@RequestBody KnowEntity knowEntity){
        Integer i = knowService.add(knowEntity);
        if(i>0){
            return "success";
        }
        else {
            return "fail";
        }
    }

    @PostMapping("/deleteById/{id}")
    public String deleteById(@PathVariable Long id){
        Integer i =knowService.deleteById(id);
        if(i>0){
            return "success";
        }
        else {
            return "fail";
        }
    }
    @PostMapping("/update")
    public String update(@RequestBody KnowEntity knowEntity ){
        Integer i = knowService.update(knowEntity);
        if(i>0){
            return "success";
        }
        else {
            return "fail";
        }
    }

    @PostMapping("/getById/{id}")
    public KnowEntity getById(@PathVariable Long id){
        return knowService.getById(id);
    }
}
